package com.xidian.zhiancloud.controller.equipFacility.ohManager;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.qo.equipFacility.OhLedgerQO;
import com.xidian.zhiancloud.service.equipFacility.OhRegisterService;
import com.xidian.zhiancloud.vo.equipFacility.OhLedgerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 检修台账
 * @author zhangyifan
 */
@RestController
@RequestMapping("/OhLedger")
public class OhLedgerController extends BaseController {
    @Autowired
    private OhRegisterService ohRegisterService;

    /**
     * 根据id查询
     * @param id 检修登记id
     * @return 返回检修登记信息
     */
    @GetMapping("/getById")
    public ResultDTO<OhLedgerVO> getById(Long id){
        return ResultDTO.successOf(ohRegisterService.getLedgerById(id),GeneralResponseEnums.SUCCESS );
    }

    /**
     * 列表查询
     * @param ohLedgerQO 传递参数
     * @return 返回列表
     */
    @GetMapping("/getLedgerListByQO")
    public ResultDTO<IPage<OhLedgerVO>> getLedgerListByQO(OhLedgerQO ohLedgerQO) {
        if (ohLedgerQO.getCurrent() == null || ohLedgerQO.getSize() == null) {
            return ResultDTO.errorOf(GeneralResponseEnums.REQUEST_ERROR);
        }
        ohLedgerQO.setCompanyId(getSessionUserCompanyId());
        return ResultDTO.successOf(ohRegisterService.getLedgerListByQO(ohLedgerQO), GeneralResponseEnums.SUCCESS);
    }


}
